﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;

namespace PersonaLibrary.ViewModel.PrintViewModel
{
    internal sealed class DocumentPaginatorWrapper : DocumentPaginator, IDocumentPaginatorSource
    {
        private readonly DocumentPaginator _source;
    	private PageRange? _range;

        public DocumentPaginatorWrapper(DocumentPaginator source)
        {
        	_source = source;
        }

        public override DocumentPage GetPage(int pageNumber)
        {
			if (_range == null)
				return _source.GetPage(pageNumber);

            return _source.GetPage(_range.Value.PageFrom + pageNumber - 1);
        }

        public override bool IsPageCountValid
        {
            get
            {
            	return _source.IsPageCountValid;
            }
        }

        public override int PageCount
        {
            get
            {
				if (_range == null)
					return _source.PageCount;
				
            	return _range.Value.PageTo - _range.Value.PageFrom + 1;
            }
        }

        public override Size PageSize
        {
            get
            {
            	return _source.PageSize;
            }

            set
            {
                _source.PageSize = value;
            }
        }

        public override IDocumentPaginatorSource Source
        {
            get
            {
                return this;
            }
        }

        public DocumentPaginator DocumentPaginator
        {
            get { return this; }
        }

    	public PageRange? Range
    	{
    		set
    		{
    			_range = value;
    		}
			get
			{
				return _range;
			}
    	}
    }
}
